package com.app.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.app.common.dataDictionary.DE.DE_USERID;
import com.app.common.dataDictionary.DE.DE_QRCODEID;
import com.app.common.dataDictionary.DE.DE_QRCODETYPE;
import com.app.common.dataDictionary.DE.DE_OPPTIME;
import com.app.common.dataDictionary.DE.DE_BZ;


/**
 * 二维码扫描维护表day
 */
@PersistObject
public class QrcodemaintainDayPO extends AbsPersistObject {
	//private static final long serialVersionUID = -2421242740929676236L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(5);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(5);
	
	static{
		HAS_DEFAULT_VALUE.set(2, true);
		fieldIndex.put("userid",0);fieldIndex.put("qrcodeid",1);fieldIndex.put("qrcodetype",2);fieldIndex.put("opptime",3);fieldIndex.put("bz",4);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "qrcodemaintain_day";

	/**
	 * 用户id
	 */
	private DE_USERID userid = DE_USERID.getTemplateInstance();

	/**
	 * 二维码id
	 */
	private DE_QRCODEID qrcodeid = DE_QRCODEID.getTemplateInstance();

	/**
	 * 二维码类型
	 */
	private DE_QRCODETYPE qrcodetype = DE_QRCODETYPE.getTemplateInstance();

	/**
	 * 操作时间
	 */
	private DE_OPPTIME opptime = DE_OPPTIME.getTemplateInstance();

	/**
	 * 备注
	 */
	private DE_BZ bz = DE_BZ.getTemplateInstance();


	public QrcodemaintainDayPO(){
		this.insertState = new BitSet(5);
		this.updateState = new BitSet(5);
	}

	
	/**
	 * 获取 "用户id" 值
	 */	
	public DE_USERID getUserid(){
		return  userid;
	}
	
	/**
	 * 设置 "用户id" 值
	 */
	public void setUserid(DE_USERID userid) {
		if(userid == null){
			userid= DE_USERID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.userid = userid;
	}
	
	/**
	 * 获取 "二维码id" 值
	 */	
	public DE_QRCODEID getQrcodeid(){
		return  qrcodeid;
	}
	
	/**
	 * 设置 "二维码id" 值
	 */
	public void setQrcodeid(DE_QRCODEID qrcodeid) {
		if(qrcodeid == null){
			qrcodeid= DE_QRCODEID.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.qrcodeid = qrcodeid;
	}
	
	/**
	 * 获取 "二维码类型" 值
	 */	
	public DE_QRCODETYPE getQrcodetype(){
		return  qrcodetype;
	}
	
	/**
	 * 设置 "二维码类型" 值
	 */
	public void setQrcodetype(DE_QRCODETYPE qrcodetype) {
		if(qrcodetype == null){
			qrcodetype= DE_QRCODETYPE.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.qrcodetype = qrcodetype;
	}
	
	/**
	 * 获取 "操作时间" 值
	 */	
	public DE_OPPTIME getOpptime(){
		return  opptime;
	}
	
	/**
	 * 设置 "操作时间" 值
	 */
	public void setOpptime(DE_OPPTIME opptime) {
		if(opptime == null){
			opptime= DE_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.opptime = opptime;
	}
	
	/**
	 * 获取 "备注" 值
	 */	
	public DE_BZ getBz(){
		return  bz;
	}
	
	/**
	 * 设置 "备注" 值
	 */
	public void setBz(DE_BZ bz) {
		if(bz == null){
			bz= DE_BZ.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.bz = bz;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {userid,qrcodeid,qrcodetype,opptime,bz};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"userid","qrcodeid","qrcodetype","opptime","bz"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return userid;
		case 1 : return qrcodeid;
		case 2 : return qrcodetype;
		case 3 : return opptime;
		case 4 : return bz;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public QrcodemaintainDayPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setUserid(null);
					} else {
						setUserid((DE_USERID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setQrcodeid(null);
					} else {
						setQrcodeid((DE_QRCODEID) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setQrcodetype(null);
					} else {
						setQrcodetype((DE_QRCODETYPE) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setOpptime(null);
					} else {
						setOpptime((DE_OPPTIME) fieldValue);
					}
					return this;
				}
				
				case 4 : {
					if (fieldValue == null) {
						setBz(null);
					} else {
						setBz((DE_BZ) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected QrcodemaintainDayPO clone() {
		QrcodemaintainDayPO t = new QrcodemaintainDayPO();
		
		t.setUserid(this.userid);
		t.setQrcodeid(this.qrcodeid);
		t.setQrcodetype(this.qrcodetype);
		t.setOpptime(this.opptime);
		t.setBz(this.bz);

		return t;
	}

	@Override
	public QrcodemaintainDayPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("userid")){
			value = dataMap.get("userid");
			
			if (value == null) {
				this.setUserid(null);
			} else {
				if (value instanceof DE_USERID) {
					this.setUserid((DE_USERID) value);
				}
			    else {
					this.setUserid(new DE_USERID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("qrcodeid")){
			value = dataMap.get("qrcodeid");
			
			if (value == null) {
				this.setQrcodeid(null);
			} else {
				if (value instanceof DE_QRCODEID) {
					this.setQrcodeid((DE_QRCODEID) value);
				}
			    else {
					this.setQrcodeid(new DE_QRCODEID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("qrcodetype")){
			value = dataMap.get("qrcodetype");
			
			if (value == null) {
				this.setQrcodetype(null);
			} else {
				if (value instanceof DE_QRCODETYPE) {
					this.setQrcodetype((DE_QRCODETYPE) value);
				}
			    else {
					this.setQrcodetype(new DE_QRCODETYPE(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("opptime")){
			value = dataMap.get("opptime");
			
			if (value == null) {
				this.setOpptime(null);
			} else {
				if (value instanceof DE_OPPTIME) {
					this.setOpptime((DE_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setOpptime(new DE_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setOpptime(new DE_OPPTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("bz")){
			value = dataMap.get("bz");
			
			if (value == null) {
				this.setBz(null);
			} else {
				if (value instanceof DE_BZ) {
					this.setBz((DE_BZ) value);
				}
			    else {
					this.setBz(new DE_BZ(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("userid", userid);
		dataMap.put("qrcodeid", qrcodeid);
		dataMap.put("qrcodetype", qrcodetype);
		dataMap.put("opptime", opptime);
		dataMap.put("bz", bz);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("userid", (userid==null?null:userid.value));
		dataMap.put("qrcodeid", (qrcodeid==null?null:qrcodeid.value));
		dataMap.put("qrcodetype", (qrcodetype==null?null:qrcodetype.value));
		dataMap.put("opptime", (opptime==null?null:opptime.value));
		dataMap.put("bz", (bz==null?null:bz.value));
		
		return dataMap;
	}
	
	@Override
	public QrcodemaintainDayPO newInstance() {
		return new QrcodemaintainDayPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{userid,qrcodeid};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (userid.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段userid不允许为空\n");
				}
				if (qrcodeid.value == null && !HAS_DEFAULT_VALUE.get(1)) {
					errorMsg.append("字段qrcodeid不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && userid.value == null) {
			errorMsg.append("字段userid不允许为空\n");
		}
		if (updateState.get(1) && qrcodeid.value == null) {
			errorMsg.append("字段qrcodeid不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("userid:").append(userid.value!=null?userid:"").append(" ").append("qrcodeid:").append(qrcodeid.value!=null?qrcodeid:"").append(" ").append("qrcodetype:").append(qrcodetype.value!=null?qrcodetype:"").append(" ").append("opptime:").append(opptime.value!=null?opptime:"").append(" ").append("bz:").append(bz.value!=null?bz:"").append(" ");
		return str.toString();
	}
	
}
